require "watir" 
require "mysql"
require "DBI"

email_init = "zhangxmbxy@hotmail.com"

browser = Watir::Browser.start  "http://www.shermanstravel.com/luxury/"
browser.text_field(:id, "txtNewsletterSignupEmail").set(email_init)
browser.button(:src,"http://i.stcdn.net/btn_signmeup_light_orange.jpg").click
browser.text_field(:id, "lux_my_zip").set("10025")
browser.checkbox(:id, "si_1").set
browser.checkbox(:id, "si_9").set
browser.text_field(:id, "lux_city").set("ny")
browser.text_field(:id, "lux_addr_two").set("APT 3e")
browser.text_field(:id, "lux_addr_one").set("219 W 100")
browser.select_list(:id, "people_address_state_or_territory").set("NJ")
browser.select_list(:id, "people_address_state_or_territory").set("NY")
browser.text_field(:id, "lux_zip").set("10024")
browser.select_list(:id, "people_address_country_id").set("Tuvalu")
browser.select_list(:id, "people_address_country_id").set("United States")
browser.text_field(:id, "lux_phone").set("347-226-1816-1")
browser.text_field(:id, "lux_phone").set("347-226-1816")
browser.checkbox(:id, "magazine_checkbox").set
browser.button(:value,"Submit").click

# check the database information
begin
  
   my = Mysql.new("db1.shermanstravel.com", "webuser", "0xQ!=_7R", 'st')
#  res = my.query("SELECT * FROM people where email = 'zhangxmbxy@hotmail.com' ")   
   res = my.query("SELECT * FROM people where email = '"+ email_init +"' limit 10 " )  
   if (res) 
   res.each do |row|   
   printf "The information with emails address '"+email_init+"' is "  
   printf "\n\n" 
   printf "First Name: %s, Last Name : %s\n", row[3], row[4]
   printf "\n"
   end
   printf "there is no information with email '"+email_init+"' " 
   

  end
  
####
  res2 = my.query("SELECT postal_code FROM people p, people_addresses pa where p.email = '"+email_init+"' and p.address_id = pa.id")
      if (!res2) 
        printf "error, there is no address information with this email '"+email_init+"' "
		printf "\n"
      end
  res2.each do |row|
	  if (row[0])
		printf "The postal-code information with '"+email_init+"' has been stored successfully"
		printf "\n"
		printf "postal code: %s\n", row[0]		
	   end
	 printf "postal-code information is not stored properly with email '"+email_init+"' "
	 printf "\n"  
  end
end


